package subject_set.weekly_competition.day10_15;

import java.util.Arrays;

/**
 * @author haomin
 * @date 2022/10/15 22:21
 **/
public class Num3 {
    public static void main(String[] args) {
        minimizeArrayValue(new int[]{13,13,20,0,8,9,9});
    }
    public static int minimizeArrayValue(int[] nums) {
        int max = 0;
        while(true){
            for(int i = 0; i < nums.length; ++i) max = Math.max(max, nums[i]);
            for(int i = 1; i < nums.length; ++i){
                while(nums[i-1] < (max -1) && nums[i] > 0){
                    nums[i-1]++;
                    nums[i]--;
                    max = 0;
                    for(int j = 0; j < nums.length; ++j) max = Math.max(max, nums[j]);
                }
            }
            System.out.println(Arrays.toString(nums));
            System.out.println();
            int newMax = 0;
            for(int i = 0; i < nums.length; ++i) newMax = Math.max(newMax, nums[i]);
            if(max == newMax) break;
            max = newMax;
        }
        return max;
    }
}